package com.fallsvc.re.networkprogramming.timer;

class MyTask implements Comparable<MyTask> {
    public Runnable runnable;
    // 为了⽅便后续判定, 使⽤绝对的时间戳.
    public long time;

    public MyTask(Runnable runnable, long delay) {
        this.runnable = runnable;// 取当前时刻的时间戳 + delay, 作为该任务实际执⾏的时间戳
        this.time = System.currentTimeMillis() + delay;
    }

    @Override
    public int compareTo(MyTask o) {
        // 这样的写法意味着每次取出的是时间最⼩的元素.
        // 到底是谁减谁?? 俺也记不住!!! 随便写⼀个, 执⾏下, 看看效果~~
        return (int) (this.time - o.time);
    }
}